var Generator = require('yeoman-generator');

module.exports = class extends Generator {
  // The name `constructor` is important here
  constructor(args, opts) {
    // Calling the super constructor is important so our generator is correctly set up
    super(args, opts);
  }

  async initPackage() {
    const answer = await this.prompt({
      type: 'input',
      name: 'name',
      message: 'Your project name',
      default: this.appname.replace(/\s/g, '-'),
    });

    const pkgJSon = {
      name: answer.name,
      version: '1.0.0',
      main: 'index.js',
      license: 'MIT',
      dependencies: {
      },
    };

    this.fs.extendJSON(this.destinationPath('package.json'), pkgJSon);
    this.env.options.nodePackageManager = 'yarn';
  
    await this.addDependencies(['vue']);
    await this.addDevDependencies(['webpack', 'webpack-cli', 'copy-webpack-plugin', 'vue-loader', 'vue-template-compiler', 'css-loader', 'vue-style-loader']);

    this.fs.copyTpl(
      this.templatePath('HelloWorld.vue'),
      this.destinationPath('src/HelloWorld.vue'),
    );
    this.fs.copyTpl(
      this.templatePath('webpack.config.js'),
      this.destinationPath('webpack.config.js'),
    );
    this.fs.copyTpl(
      this.templatePath('main.js'),
      this.destinationPath('src/main.js'),
    );
    this.fs.copyTpl(
      this.templatePath('index.html'),
      this.destinationPath('src/index.html'),
      { title: answer.name },
    );
  }
};
